<?php 
/**
 * @version			$Id$
 * @author			Richard Asp
 * @package			Joomla
 * @subpackage		gnudoor
 * @copyright		(C) 2010 gnudoor LLC
 * @license      GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

defined( '_JEXEC' ) or die( 'Restriced access' );
JHTML::_('stylesheet', 'myform.css','components/com_gnudoor/assets/css/');
JHTML::_('behavior.mootools');
$params = &JComponentHelper::getParams( 'com_gnudoor' );
$topalias = $params->get( 'Default Page Top' );
$bottomalias = $params->get( 'Default Page Bottom' );

// $model =& $this->getModel('Newtask');
// $topID = $model->getArticleID($topalias);
// $topid = $topID->id;
// $bottomID = $model->getArticleID($bottomalias);
// $bottomid = $bottomID->id;
?>
<h1>Online Booking System</h1>
<?php // echo file_get_contents($this->articlebase . $topid);?>
<div id="newtask" class="myform">
<?php 
if (isset($this->dateparam)) {
	$date = date_create($this->dateparam);
} else {
	$date = date_create();
}
$arr = date_parse(date_format($date,DATE_RFC822));
$timestamp = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']);
$arr = getdate($timestamp);
$firstday = $date;
$firstday->modify('-'.$arr['wday'].' day');
$currday = clone $firstday;		
$prevweek = clone $currday;
$prevweek->modify('-7 day');
$nextweek = clone $currday;
$nextweek->modify('+7 day');
$forwardDate = '<a href=index.php?option=com_gnudoor&controller=appointments&task=default&date=' . date_format($prevweek,'Ymd') . '><<</a>';
$backwardDate = '<a href=index.php?option=com_gnudoor&controller=appointments&task=default&date=' . date_format($nextweek,'Ymd') . '>>></a>';

?>
<!--  render week calendar view -->

<div id="pbbooking">
<table class="calendar">
<tr class="cal_nav_row">
<td></td>
<td><?php echo $forwardDate; ?></td>
<td colspan="<?php echo count($this->timeslots)-2; ?> "></td>
<td><?php echo  $backwardDate; ?></td>
</tr>
<tr class="cal_header_row"><td></td>

<?php 
foreach ($this->timeslots as $timeslot) {
	echo '<td>'.$timeslot['english'].'</td>';
}
?>
</tr>

<?php 
for($i=0;$i<7;$i++) { ?>
<tr class="cal_data_row">
	<td class="cal_date_cell"><?php echo $this->days[$i].'&nbsp;'; echo date_format($currday,'M/d'); ?></td>

<?php 	
for ($j=0;$j<count($this->timeslots);$j++) {
	if ($this->block_same_day == 1) {
		$currday->setTime(0,0);
	} else {
		$currday->setTime($this->timeslots[$j]['start_hour'],$this->timeslots[$j]['start_min']);
	}
	if ($this->now <= $currday) {
		//	$model =& $this->getModel('Appointments');			
		if ($this->cal->isFree($currday,$j)) {
			echo '<td class="cal_free_cell">'."\n";
			echo sprintf("<a href=index.php?option=com_gnudoor&controller=appointments&task=create&date=%s&slot=%s>FREE</a>",
					date_format($currday,'Ymd'),$j);
		} else {
			echo '<td class="cal_busy_cell">'."\n";
			echo "BUSY";
		}
		echo '</td>';
	} else {
		echo '<td class="cal_busy_cell">'."\n";
		echo "PAST";
		echo '</td>'; 
	}
}
	
$currday->modify('+1 day');
echo '</tr>'."\n";
}
?>

</table>
</div>


</div>
<?php // echo file_get_contents($this->articlebase . $bottomid);?>